const express = require('express')
const autoPort = require('./utils/autoPort.js')
const app = express();
const UserRouter = require('./routers/userRounter.js')
const ImagesRouter = require('./routers/imagesRounter.js')
const goodRouter = require('./routers/goodRounter.js')
const ServerConfig = require('./server.config.js')
const session = require('express-session')

app.use(session({
  secret: 'its my secret',
  cookie: { maxAge: 600000 }, // value of maxAge is defined in milliseconds. 
  resave: false,
  rolling: false,
  saveUninitialized: true
}))
const cors = require('cors')
//服务器入口方法
async function main(app,port){
    let msg = await autoPort(port,app)
    console.log(msg)
}
//服务器入口方法

//解决跨域问题
app.use(cors())
//json解析中间件
app.use(express.json())
//表单解析中简件
app.use(express.urlencoded({extended:false}))
//登陆界面的用户路由
app.use('',UserRouter)
//图片数据的路由
app.use('',ImagesRouter)
//货物信息的路由
app.use('',goodRouter)
module.exports = {
  app:app,
  port: ServerConfig.port
}